﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using Sharebert.LinkLayerLibrary;
using Sharebert.LoggingLibrary.API;

namespace Sharebert.OverlayLibrary.API
{
    /// <summary>
    /// Implementations of IBootstrapClient are used to communicate with the bootstrap server. The bootstrap server provides a list 
    /// of currently active peers. 
    /// </summary>
    public interface IBootstrapClient
    {

        /// <summary>
        /// Requests a list of active peers from the bootstrap server.
        /// </summary>
        /// <param name="n">The number of peers, that the server should give</param>
        /// <exception cref="NetworkException">Could not connect or sending message failed</exception>
        void RequestPeers(int n);

        /// <summary>
        /// Sends a ping message to the server to signal that the peer is still alive.
        /// </summary>
        void PingBootstrapServer();

        /// <summary>
        /// Peer is going offline and tells the bootstrap server to remove him from the list.
        /// </summary>
        /// <exception cref="NetworkException">Could not connect to server or send message</exception>
        void Offline();

        /// <summary>
        /// The hostname or IP of the bootstrap server.
        /// </summary>
        string ServerAddress { get; }

        /// <summary>
        /// The port of the bootstrap server.
        /// </summary>
        int ServerPort { get; }

        /// <summary>
        /// The IP to listen for new peer connections.
        /// </summary>
        string ListenIP { get; }

        /// <summary>
        /// The port to listen for new peer connections.
        /// </summary>
        int ListenPort { get; }

        /// <summary>
        /// Sending and receiving messages will timeout after the specified time in seconds.
        /// </summary>
        int Timeout { get; set; }

        /// <summary>
        /// Gets the current logger.
        /// </summary>
        ILogger Logger { get; }

        /// <summary>
        /// The server did not respond after Timeout seconds.
        /// </summary>
        event EventHandler<EventArgs> ConnectionLost;

        /// <summary>
        /// Received a peer list from the server.
        /// </summary>
        event EventHandler<PeerListReceivedEventArgs> PeerListReceived;

    }
}
